<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="zh">
<head>
<%@include file="../../commons/meta.jsp"%>

<c:set var="baseUrl" value="${ctx}api/major-recruit-plan/" scope="request" />
<link rel="stylesheet" href="${ctx}assets/plugins/pure/pure-min.css" media="all" />
<script type="text/javascript" src="${ctx}assets/plugins/plupload/2.2.1/js/plupload.full.min.js"></script>
<script type="text/javascript" src="${ctx}assets/plugins/plupload/2.2.1/js/i18n/zh_CN.js"></script>
<script type="text/javascript">
    function validateForm() {
        if (empty($("#filepath").val())) {
            alertError('<fmt:message key="press.pleaseClickFileUploadUploadFile"/>');
            return false;
        }

        $("#forms").submit();
    }
    //  关闭弹出框 
    jQuery(document).ready(function() {
        $("#back_btn").click(function() {
            window.location.href = "${baseUrl}"
        });
    });
</script>
</head>
<body>
    <%@include file="../../commons/head.jsp"%>
    <div class="content">
        <%@include file="../../commons/menu.jsp"%>
        <!--右侧展示部分-->
        <div class="right-zq">
            <!--center content-->
            <div class="dynamic">
                <div class="role dynamiclayer" style="display: block;">
                    <div class="title orange2">
                        <span class="left">高校信息管理</span>
                        <label> > </label><span>招生计划(专业)管理</span>
                        <label> > </label><span>导入</span>
                    </div>
                    <form class="" id="forms" method="post" action="${baseUrl}importData">
                        <div class="news-table">
                            <table>
                                <tr>
                                    <td>
                                    <input id="fileNameOrg" name="fileNameOrg" type="hidden" style="display: none;" placeholder="" value="" />
                                    </td>
                                    <td>
                                    <input id="filepath" name="filepath" type="hidden" style="display: none;" placeholder="" value="" />
                                    </td>
                                </tr>
                                <tr>
                                    <td class="item"><fmt:message key="press.file" /></td>
                                    <td><span id="filelinkfull"><a id="filelinkfulla" href="#" target="_blank"></a></span></td>
                                </tr>
                                <tr>
                                    <td class="item" id="container"><fmt:message key="press.upload" /></td>
                                    <td width="40%"><a id="pickfiles" href="javascript:void(0)"><fmt:message key="press.selectFileUpload" /></a></td>
                                </tr>
                                <tr>
                                    <td></td>
                                    <td>
                                        <button class="orange2" type="button" onclick="validateForm()">
                                            <fmt:message key='sys.save' />
                                            &nbsp;<i class="fa fa-floppy-o"></i>
                                        </button> &nbsp;&nbsp;
                                        <button class="orange2" type="button" id="back_btn">
                                            <fmt:message key='sys.exit' />
                                            &nbsp;<i class="fa fa-undo"></i>
                                        </button>
                                    </td>
                                    <td></td>
                                </tr>
                            </table>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <%@include file="../../commons/footpop.jsp"%>
    <!-- 页尾，提示消息 -->
    <jsp:include page="../../commons/foot_message.jsp"></jsp:include>
    <script>
                    var jsonDataReturn = new Array();
                    var arrImageName = new Array();
                    // "营业执照文件", extensions : "png,jpg,gif,jpeg"
                    function getUploader(pickfiles, container, url, upload,
                            title, extensions) {
                        return new plupload.Uploader(
                                {
                                    rruntimes : 'html5,flash,silverlight,html4',
                                    max_file_count : 10,
                                    chunk_size : '50mb',
                                    browse_button : pickfiles, // you can pass an id...
                                    container : document
                                            .getElementById(container), // ... or DOM Element itself 
                                    url : url,//上传路径
                                    flash_swf_url : '${ctx}assets/plugins/plupload/2.2.1/js/Moxie.swf',
                                    silverlight_xap_url : '${ctx}assets/plugins/plupload/2.2.1/js/Moxie.xap',
                                    multipart : true,
                                    multipart_params : {
                                        path : upload
                                    },
                                    filters : {
                                        min_file_size : "1kb",
                                        prevent_duplicates : false,
                                        max_file_size : '50mb',// do not let files of size larger than the maximum to the queue, and
                                        mime_types : [ {
                                            title : title,
                                            extensions : extensions
                                        } ]
                                    },
                                    init : {
                                        PostInit : function(uploader) {
                                        },
                                        FilesAdded : function(uploader, files) {
                                            uploader.start();
                                        },
                                        UploadFile : function(uploader, file) {
                                            layer.load(0, {
                                                shade : [ 0.8, '#393D49' ]
                                            });
                                        },
                                        FileUploaded : function(uploader, file,
                                                responseObject) {
                                            //更新到数据库widgetFileDb   {"flag":true,"msg":"上传成功","nameNew":"06fedc0396f5431eaaadcc7087fa13c0.png","nameOrg":"111.png","path":"upload/201612/01/06fedc0396f5431eaaadcc7087fa13c0.png","pathUrl":"http://file.worthcw.cn/upload/201612/01/06fedc0396f5431eaaadcc7087fa13c0.png"}
                                            if (responseObject != null) {
                                                var jsonData = JSON
                                                        .parse(responseObject.response); //eval("(" + responseObject.response + ")");
                                                if (jsonData.flag) {
                                                    updateToDb(jsonData);
                                                } else {
                                                    alertError("<fmt:message key='press.uploadFailed'/>!");//$('#'+file.id + ' > b').html("<span style='color:red'>&nbsp;&nbsp;上传失败</span>");
                                                }
                                                layer.closeAll("loading");
                                            }
                                            uploader.refresh();
                                        },
                                        Error : function(uploader, err) {
                                            layer.closeAll("loading");
                                            alertError(err.message);
                                            uploader.refresh();
                                        }
                                    }
                                });
                    }

                    /**初始化文件上传*/
                    function getUploaderInit() {
                        return getUploader("pickfiles", "container",
                                "${pageContext.request.contextPath}/files",
                                "newsfiles", "Excel文件","xls,xlsx");
                    }

                    var uploader = getUploaderInit();
                    uploader.init();

                    //回掉吧
                    function updateToDb(responseObject) {
                        try {
                            //Object { flag: true, msg: "上传成功", nameNew: "94c3fae4b9f043d38d6332ad3f366e36.jpg", nameOrg: "60kb201282413335761587.jpg", path: "newsfiles/2017/03/20/94c3fae4b9f043…", pathUrl: "http://files.zc.com/newsfiles/2017/…", size: 60551 }
                            debugs(responseObject);
                            var jsonData = responseObject;//JSON.parse(responseObject);
                            debugs(jsonData);
                            //$("#filelinkfull").html(jsonData.pathUrl);
                            $("#filelinkfulla").attr("href", jsonData.pathUrl);
                            $("#filelinkfulla").html(jsonData.nameOrg);
                            // $("#filepath").val(jsonData.path);
                            // 本地测试使用绝对路径
                            $("#fileNameOrg").val(jsonData.nameOrg);
                            $("#filepath").val(jsonData.pathUrl);
                            $("#filepathspan").html(jsonData.pathUrl);
                            alertOk("<fmt:message key='press.uploadSuccess'/>");
                        } catch (err) {
                            $("#filelinkfulla").attr("href", "#");
                            $("#filelinkfulla").html("");
                            $("#filepath").val("");
                            $("#filepathspan").html("");
                            alertError("<fmt:message key='press.uploadFailed'/>");
                        }
                    }

                    /* jQuery(document).ready(function() {
                        var webStatust = $("#webStatus").html();
                        if(empty(webStatust)){
                            return ;
                        }else if(webStatust == 200) {
                            parent.listFormPageSearch(1);
                        }
                    });  */
                </script>
</body>
</html>
